package fr.umlv.m2.recipes.ideas.sqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import fr.umlv.m2.recipes.ideas.dao.IngredientDAO;
import fr.umlv.m2.recipes.ideas.dao.KeywordDAO;
import fr.umlv.m2.recipes.ideas.dao.RecipeDAO;
import fr.umlv.m2.recipes.ideas.dao.RecipeToIngredientDAO;
import fr.umlv.m2.recipes.ideas.dao.RecipeToKeywordDAO;
import fr.umlv.m2.recipes.ideas.dao.StepDAO;

/**
 * Tool uses to handle the database operations
 * @author Christophe Chillan
 *
 */
public class SQLiteDbRecipes extends SQLiteOpenHelper {
	
	private final RecipeDAO recipesDAO;
	private final IngredientDAO ingredientDAO;
	private final StepDAO stepDAO;
	private final KeywordDAO keywordDAO;
	private final RecipeToKeywordDAO recipesToKeyword;
	private final RecipeToIngredientDAO recipesToIngredient;
	

	/**
	 * Create a {@link SQLiteOpenHelper} instance
	 * @param context
	 * @param name
	 * @param factory
	 * @param version
	 */
	public SQLiteDbRecipes(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
		recipesDAO = new RecipeDAO();
		ingredientDAO = new IngredientDAO();
		stepDAO = new StepDAO();
		keywordDAO = new KeywordDAO();
		recipesToKeyword = new RecipeToKeywordDAO();
		recipesToIngredient = new RecipeToIngredientDAO();
	}

	/**
	 * @see SQLiteOpenHelper
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		recipesDAO.onCreate(db);
		ingredientDAO.onCreate(db);
		keywordDAO.onCreate(db);
		recipesToKeyword.onCreate(db);
		stepDAO.onCreate(db);
		recipesToIngredient.onCreate(db);
	}

	/**
	 * @see SQLiteOpenHelper
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
		recipesDAO.onUpgrade(db);
		ingredientDAO.onUpgrade(db);
		stepDAO.onUpgrade(db);
		keywordDAO.onUpgrade(db); 
		recipesToKeyword.onUpgrade(db);
		recipesToIngredient.onUpgrade(db);
	}

	/**
	 * Get the {@link RecipeDAO} uses in the {@link SQLiteDbRecipes} instance
	 * @return {@link RecipeDAO}
	 */
	public RecipeDAO getRecipesDao() {
		return recipesDAO;
	}

	/**
	 * Get the {@link IngredientDAO} uses in the {@link SQLiteDbRecipes} instance
	 * @return {@link IngredientDAO}
	 */
	public IngredientDAO getIngredientDao() {
		return ingredientDAO;
	}

	/**
	 * Get the {@link StepDAO} uses in the {@link SQLiteDbRecipes} instance
	 * @return {@link StepDAO}
	 */
	public StepDAO getStepDao() {
		return stepDAO;
	}
	
	/**
	 * Get the {@link KeywordDAO} uses in the {@link SQLiteDbRecipes} instance
	 * @return {@link KeywordDAO}
	 */
	public KeywordDAO getKeywordDao(){
		return keywordDAO;
	}

	/**
	 * Get the {@link RecipeToKeywordDAO} liaison uses in the {@link SQLiteDbRecipes} instance
	 * @return {@link RecipeToKeywordDAO}
	 */
	public RecipeToKeywordDAO getRecipesToKeywordDao() {
		return recipesToKeyword;
	}

	/**
	 * Get the {@link RecipeToIngredientDAO} liaison uses in the {@link SQLiteDbRecipes} instance
	 * @return {@link RecipeToIngredientDAO}
	 */
	public RecipeToIngredientDAO getRecipesToIngredientDao() {
		return recipesToIngredient;
	}
	

}
